<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>module SmartSearch::InstanceMethods - SmartSearch</title>

<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>


<body id="top" class="module">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../index.html">Home</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/smart_search.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    
    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-i-clear_search_tags">#clear_search_tags</a>
    
    <li><a href="#method-i-create_search_tags">#create_search_tags</a>
    
    <li><a href="#method-i-result_template_path">#result_template_path</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    
    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../SmartSearch.html">SmartSearch</a>
  
    <li><a href="../SmartSearch/ClassMethods.html">SmartSearch::ClassMethods</a>
  
    <li><a href="../SmartSearch/Config.html">SmartSearch::Config</a>
  
    <li><a href="../SmartSearch/InstanceMethods.html">SmartSearch::InstanceMethods</a>
  
    <li><a href="../SmartSearch/SmartSearchEngine.html">SmartSearch::SmartSearchEngine</a>
  
    <li><a href="../SmartSearchHistory.html">SmartSearchHistory</a>
  
    <li><a href="../SmartSearchIgnoreWord.html">SmartSearchIgnoreWord</a>
  
    <li><a href="../SmartSearchTag.html">SmartSearchTag</a>
  
    <li><a href="../SmartSimilarity.html">SmartSimilarity</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="module">module SmartSearch::InstanceMethods</h1>

  <div id="description" class="description">
    
<p>Instance Methods for ActiveRecord</p>

  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    <!-- Methods -->
    
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-clear_search_tags" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">clear_search_tags</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Remove search data for the instance from the index</p>
          

          
          <div class="method-source-code" id="clear_search_tags-source">
            <pre><span class="ruby-comment"># File lib/smart_search.rb, line 193</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">clear_search_tags</span>
  <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span>.<span class="ruby-identifier">nil?</span>
    <span class="ruby-constant">SmartSearchTag</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">execute</span>(<span class="ruby-node">&quot;DELETE from #{SmartSearchTag.table_name} where `table_name` = &#39;#{self.class.table_name}&#39; and entry_id = #{self.id}&quot;</span>)
  <span class="ruby-keyword">end</span>  
<span class="ruby-keyword">end</span></pre>
          </div><!-- clear_search_tags-source -->
          
        </div>

        

        
      </div><!-- clear_search_tags-method -->

    
      <div id="method-i-create_search_tags" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">create_search_tags</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>create search tags for this very record based on the attributes defined in
&#39;:on&#39; option passed to the &#39;Class.smart_search&#39; method</p>
          

          
          <div class="method-source-code" id="create_search_tags-source">
            <pre><span class="ruby-comment"># File lib/smart_search.rb, line 155</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">create_search_tags</span>
  <span class="ruby-identifier">tags</span>      = []
  
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">tags</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tag</span><span class="ruby-operator">|</span>
    
    <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">tag</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
      <span class="ruby-identifier">tag</span> = {<span class="ruby-value">:field_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">tag</span>, <span class="ruby-value">:boost</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>, <span class="ruby-value">:search_tags</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&quot;&quot;</span>} 
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">tag</span>[<span class="ruby-value">:search_tags</span>] = <span class="ruby-string">&quot;&quot;</span>
      <span class="ruby-identifier">tag</span>[<span class="ruby-value">:boost</span>] <span class="ruby-operator">||=</span> <span class="ruby-value">1</span>
    <span class="ruby-keyword">end</span>    
    
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">tag</span>[<span class="ruby-value">:field_name</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>)
      <span class="ruby-identifier">tag</span>[<span class="ruby-value">:search_tags</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">tag</span>[<span class="ruby-value">:field_name</span>]).<span class="ruby-identifier">to_s</span>
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">tag</span>[<span class="ruby-value">:field_name</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
      <span class="ruby-identifier">tag_methods</span> = <span class="ruby-identifier">tag</span>[<span class="ruby-value">:field_name</span>].<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;.&quot;</span>)  
      <span class="ruby-identifier">tagx</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">tag_methods</span>[<span class="ruby-value">0</span>])
      <span class="ruby-identifier">tag_methods</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">tagx</span> = <span class="ruby-identifier">tagx</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">x</span>) <span class="ruby-keyword">rescue</span> <span class="ruby-string">&quot;&quot;</span>
      <span class="ruby-keyword">end</span>
      <span class="ruby-identifier">tag</span>[<span class="ruby-value">:search_tags</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">tagx</span>.<span class="ruby-identifier">to_s</span>  
    <span class="ruby-keyword">end</span>
    
    <span class="ruby-identifier">tag</span>[<span class="ruby-value">:search_tags</span>] = <span class="ruby-identifier">tag</span>[<span class="ruby-value">:search_tags</span>].<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot; &quot;</span>).<span class="ruby-identifier">uniq</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot; &quot;</span>).<span class="ruby-identifier">downcase</span>   
    <span class="ruby-identifier">tags</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">tag</span>
  <span class="ruby-keyword">end</span>
  
  
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">clear_search_tags</span>
    
  <span class="ruby-identifier">tags</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">SmartSearchTag</span>.<span class="ruby-identifier">create</span>(<span class="ruby-identifier">t</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-value">:table_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">table_name</span>, <span class="ruby-value">:entry_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span>))
  <span class="ruby-keyword">end</span>
   
  
<span class="ruby-keyword">end</span></pre>
          </div><!-- create_search_tags-source -->
          
        </div>

        

        
      </div><!-- create_search_tags-method -->

    
      <div id="method-i-result_template_path" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">result_template_path</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Load the result template path for this instance</p>
          

          
          <div class="method-source-code" id="result_template_path-source">
            <pre><span class="ruby-comment"># File lib/smart_search.rb, line 150</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">result_template_path</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">result_template_path</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- result_template_path-source -->
          
        </div>

        

        
      </div><!-- result_template_path-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.2.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

